import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JTextField;


public class CreateFaculty extends JFrame implements ActionListener
{
	private static final long serialVersionUID = 771828507006680634L;
	
	private JLabel name = new JLabel("Faculty Name");
	private JLabel cName = new JLabel("College Name");
	private JLabel address = new JLabel("Address of staff list page");
	private JLabel cExample = new JLabel("e.g. Dublin City University");
	private JLabel example = new JLabel("e.g. School of Computing");
	private JLabel addExample = new JLabel("e.g. http://www.dcu.ie/info/staff.php3?query=computing_staff");
	
	
	private JLabel area = new JLabel("Area of research");
	private JTextField nameText = new JTextField();
	private JTextField cNameText = new JTextField();
	private JTextField addText = new JTextField();
	private JButton create = new JButton("Create New Faculty");
	private ButtonGroup areas = new ButtonGroup();
    private JRadioButton jRadioButton1 = new JRadioButton("Biology, Life Sciences, and Environmental Science");
    private JRadioButton jRadioButton2= new JRadioButton("Business, Administration, Finance, and Economics");
    private JRadioButton jRadioButton3 = new JRadioButton("Chemistry and Materials Science");
    private JRadioButton jRadioButton4= new JRadioButton("Engineering, Computer Science, and Mathematics");
    private JRadioButton jRadioButton5= new JRadioButton("Medicine, Pharmacology, and Veterinary Science");
    private JRadioButton jRadioButton6= new JRadioButton("Physics, Astronomy, and Planetary Science");
    private JRadioButton jRadioButton7= new JRadioButton("Social Sciences, Arts, and Humanities");
    
    public CreateFaculty()
    {
    	super("Create new Faculty");
    }
    
    public void init()
    {
    	GridBagConstraints constraints = new GridBagConstraints();
    	this.setLayout(new GridBagLayout());
    	constraints.insets = new Insets(20,20,20,20);
    	
    	//add college name label
    	constraints.fill = GridBagConstraints.HORIZONTAL;
    	constraints.gridx = 0;
    	constraints.gridy = 0;
    	this.add(cName, constraints);
    	
    	// college name text box
    	constraints.insets = new Insets(20,20,20,20);
    	constraints.fill = GridBagConstraints.HORIZONTAL;
    	constraints.gridx = 1;
    	constraints.gridy = 0;
    	constraints.ipadx = 150;
    	this.add(getCNameText(), constraints);
    	constraints.ipadx = 0;
    	
    	//college name example
    	constraints.fill = GridBagConstraints.HORIZONTAL;
    	constraints.gridx = 2;
    	constraints.gridy = 0;
    	this.add(cExample, constraints);
    	
    	// faculty name label
    	constraints.fill = GridBagConstraints.HORIZONTAL;
    	constraints.gridx = 0;
    	constraints.gridy = 1;
    	this.add(name, constraints);
    	
    	//faculty name box
    	constraints.insets = new Insets(20,20,20,20);
    	constraints.fill = GridBagConstraints.HORIZONTAL;
    	constraints.gridx = 1;
    	constraints.gridy = 1;
    	constraints.ipadx = 150;
    	this.add(getNameText(), constraints);
    	constraints.ipadx = 0;
    	
    	//faulty name example
    	constraints.fill = GridBagConstraints.HORIZONTAL;
    	constraints.gridx = 2;
    	constraints.gridy = 1;
    	this.add(example, constraints);
    	
    	//address label
    	constraints.insets = new Insets(0,20,20,20);
    	constraints.fill = GridBagConstraints.HORIZONTAL;
    	constraints.gridx = 0;
    	constraints.gridy = 2;
    	this.add(address, constraints);
    	
    	//address box
    	constraints.fill = GridBagConstraints.HORIZONTAL;
    	constraints.gridx = 1;
    	constraints.gridy = 2;
    	constraints.ipadx = 150;
    	this.add(getAddText(), constraints);
    	constraints.ipadx = 0;
    	
    	//address example
    	constraints.insets = new Insets(0,20,20,20);
    	constraints.fill = GridBagConstraints.HORIZONTAL;
    	constraints.gridx = 2;
    	constraints.gridy = 2;
    	this.add(addExample, constraints);
    	
    	//area label
    	constraints.fill = GridBagConstraints.HORIZONTAL;
    	constraints.gridx = 0;
    	constraints.gridy = 4;
    	this.add(area, constraints);
    	
    	constraints.fill = GridBagConstraints.HORIZONTAL;
    	constraints.gridx = 1;
    	constraints.gridy = 4;
    	this.add(jRadioButton1, constraints);
    	
    	constraints.fill = GridBagConstraints.HORIZONTAL;
    	constraints.gridx = 1;
    	constraints.gridy = 5;
    	this.add(jRadioButton2, constraints);
    	
    	constraints.fill = GridBagConstraints.HORIZONTAL;
    	constraints.gridx = 1;
    	constraints.gridy = 6;
    	this.add(jRadioButton3, constraints);
    	
    	constraints.fill = GridBagConstraints.HORIZONTAL;
    	constraints.gridx = 1;
    	constraints.gridy = 7;
    	this.add(jRadioButton4, constraints);
    	constraints.fill = GridBagConstraints.HORIZONTAL;
    	constraints.gridx = 1;
    	constraints.gridy = 8;
    	this.add(jRadioButton5, constraints);
    	constraints.fill = GridBagConstraints.HORIZONTAL;
    	constraints.gridx = 1;
    	constraints.gridy = 9;
    	this.add(jRadioButton6, constraints);
    	constraints.fill = GridBagConstraints.HORIZONTAL;
    	constraints.gridx = 1;
    	constraints.gridy = 10;
    	this.add(jRadioButton7, constraints);

    	// create button
    	constraints.insets = new Insets(20,20,20,20);
    	constraints.fill = GridBagConstraints.HORIZONTAL;
    	constraints.gridx = 4;
    	constraints.gridy = 12;
    	this.add(getCreate(), constraints);
    	
    	//cancel button
    	JButton cancel = new JButton("Cancel");
    	cancel.addActionListener(this);
    	cancel.setActionCommand("cancel");
    	constraints.insets = new Insets(20,20,20,20);
    	constraints.fill = GridBagConstraints.HORIZONTAL;
    	constraints.gridx = 3;
    	constraints.gridy = 12;
    	this.add(cancel,constraints);
    	
    	
    	getAreas().add(jRadioButton1);
    	getAreas().add(jRadioButton2);
    	getAreas().add(jRadioButton3);
    	getAreas().add(jRadioButton4);
    	getAreas().add(jRadioButton5);
    	getAreas().add(jRadioButton6);
    	getAreas().add(jRadioButton7);
    	
    	jRadioButton1.addActionListener(this);
    	jRadioButton1.setActionCommand("bio");
    	jRadioButton2.addActionListener(this);
    	jRadioButton2.setActionCommand("bus");
    	jRadioButton3.addActionListener(this);
    	jRadioButton3.setActionCommand("chm");
    	jRadioButton4.addActionListener(this);
    	jRadioButton4.setActionCommand("eng");
    	jRadioButton5.addActionListener(this);
    	jRadioButton5.setActionCommand("med");
    	jRadioButton6.addActionListener(this);
    	jRadioButton6.setActionCommand("phy");
    	jRadioButton7.addActionListener(this);
    	jRadioButton7.setActionCommand("soc");
    	getCreate().addActionListener(this);
    	getCreate().setActionCommand("create");
    	
    	this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    	
    	//4. Size the frame.
    	this.pack();

    }

	@Override
	public void actionPerformed(ActionEvent e) 
	{
		if(e.getActionCommand().equals("create"))
		{
			if(checkInputs())
			{
				JOptionPane.showMessageDialog(this,"Faculty Added");
			}		
		}
		else if(e.getActionCommand().equals("cancel"))
		{
			reset();
			this.setVisible(false);
		}
	}
	
	public boolean checkInputs()
	{
		boolean validInput = true;
		if(getAreas().getSelection() == null)
		{
			JOptionPane.showMessageDialog(this,"You must select the Faculty's area of research");			
			return false;
		}
		if(getNameText().getText().equals(""))
		{
			JOptionPane.showMessageDialog(this,"You must give the name of the faculty");			
			return false;
		}
		if(getCNameText().getText().equals(""))
		{
			JOptionPane.showMessageDialog(this,"You must give the name of the college");			
			return false;
		}
		if(getAddText().getText().equals(""))
		{
			JOptionPane.showMessageDialog(this,"You must give the staff list address page");			
			return false;
		}
		return validInput;
	}
	
	public static void main(String [] args)
	{
		CreateFaculty cf = new CreateFaculty();
		cf.init();
	}

	public void setCreate(JButton create) {
		this.create = create;
	}

	public JButton getCreate() {
		return create;
	}
	
	public void reset()
	{
		this.getNameText().setText(null);
		this.getAddText().setText(null);
		this.getCNameText().setText(null);
		this.getAreas().clearSelection();
	}

	public void setCNameText(JTextField cNameText) {
		this.cNameText = cNameText;
	}

	public JTextField getCNameText() {
		return cNameText;
	}

	public void setNameText(JTextField nameText) {
		this.nameText = nameText;
	}

	public JTextField getNameText() {
		return nameText;
	}

	public void setAreas(ButtonGroup areas) {
		this.areas = areas;
	}

	public ButtonGroup getAreas() {
		return areas;
	}

	public void setAddText(JTextField addText) {
		this.addText = addText;
	}

	public JTextField getAddText() {
		return addText;
	}
}
